﻿using MMS.Api.Helper;
using MMS.Model.FormatModel;
using System.Linq;
using System.Web.WebPages;

namespace MMS.Api.Areas.Admin.Controllers
{
    public class MemberInfoController : BaseController
    {
        #region 1.0 分页查询  //http://localhost:16824/api/MemberInfo/GetWherePaged
        /// <summary>
        /// 
        /// </summary>
        /// <param name="id">page页码</param>
        /// <param name="id1">rows页容量</param>
        /// <returns></returns>
        public PageData<Model.MemberInfo> GetWherePaged(string id, string id1)
        {
            int pageIndex = id.AsInt();
            int pageSize = id1.AsInt();
            //1.查询数据集合
            var pageData = OpeCur.BLLSession.MemberInfo.WherePaged(pageIndex, pageSize, o => o.MIsDel == false, o => o.MId,true,"Level");
            pageData.rows = pageData.rows.Select(o => o.ToPOCO(true)).ToList();
            //2.转成json格式字符串

            return pageData;
        }
        #endregion

        #region 2.0 新增 //http://localhost:16824/api/MemberInfo/PostAdd
        public void PostAdd(Model.MemberInfo model)
        {
            OpeCur.BLLSession.MemberInfo.Add(model);
            OpeCur.BLLSession.SaveChanges();
        }
        #endregion

        #region 3.0 查找修改 //http://localhost:16824/api/MemberInfo/GetModify/1
        public Model.MemberInfo GetModify(int id)
        {
            var model = OpeCur.BLLSession.MemberInfo.Where(o => o.MId== id && o.MIsDel == false).FirstOrDefault().ToPOCO();
            return model;
        }
        #endregion

        #region 3.1 修改 //http://localhost:16824/api/MemberInfo/PostModify
        public void PostModify(Model.MemberInfo model)
        {
            OpeCur.BLLSession.MemberInfo.Modify(model, "MCardId", "MLId", "MName", "MBalances", "MIntegral", "MConsumption", "MBirthday", "MBalances", "MGender", "MOccupation", "MPhone", "MPassword", "MAddress", "MEmail", "MWechat", "MRemark");
            OpeCur.BLLSession.SaveChanges();
        }
        #endregion

        #region 4.0 删除 // http://localhost:16824/api/MemberInfo/GetRemoveById/
        public void GetRemoveById(int id)
        {
            OpeCur.BLLSession.MemberInfo.ModifyBy(o => o.MId == id, new string[] { "MIsDel" },  new object[] { true});
            OpeCur.BLLSession.SaveChanges();
        }
        #endregion
    }
}
